package com.xbongbong.saas.enums.dictionary;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import lombok.Getter;

import java.util.Objects;

/**
 * 券类型
 * @author jyh
 * @version v1.0
 * @date 2021/01/04 22:00
 * @since v1.0
 */
@Getter
public enum CouponTypeEnum {


    //全场代金券
    FULL_DISCOUNT_COUPON("1","enum.couponType.name.full_discount_coupon","fullDiscountCoupon", XbbRefTypeEnum.FULL_DISCOUNT_COUPON.getCode()),
    ;
    private String code;
    private String name;
    private String attr;
    private Integer businessType;


    CouponTypeEnum(String code, String name, String attr, Integer businessType) {
        this.code = code;
        this.name = name;
        this.attr = attr;
        this.businessType = businessType;
    }
    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }

    /**
     * 通过枚举 code 获得枚举
     *
     * @param code 枚举Code
     *
     * @return TransferStatusEnum
     */
    public static CouponTypeEnum getByBusinessType(Integer code) {
        for (CouponTypeEnum value : CouponTypeEnum.values()) {
            if (Objects.equals(value.getBusinessType(), code)) {
                return value;
            }
        }
        return FULL_DISCOUNT_COUPON;
    }

    /**
     * 通过枚举 code 获得枚举
     *
     * @param code 枚举Code
     *
     * @return TransferStatusEnum
     */
    public static CouponTypeEnum getByCode(String code) {
        for (CouponTypeEnum value : CouponTypeEnum.values()) {
            if (Objects.equals(value.getCode(), code)) {
                return value;
            }
        }
        return FULL_DISCOUNT_COUPON;
    }
}
